package com.bgds.sys.module.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bgds.sys.common.pagevo.MeasureRecordExcel;
import com.bgds.sys.common.utils.DateUtils;
import com.bgds.sys.module.entity.MeasureRecord;
import com.bgds.sys.module.entity.dto.MeasureRecordDto;
import com.bgds.sys.module.mapper.MeasureRecordMapper;
import com.bgds.sys.module.service.IMeasureRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lj
 * @since 2020-02-18
 */
@Service
public class IMeasureRecordServiceImpl extends ServiceImpl<MeasureRecordMapper, MeasureRecord> implements IMeasureRecordService {

    @Autowired
    private MeasureRecordMapper measureRecordMapper;
    /**
     * 条件分页查询设备精度管理项目测试记录

     * @param accuracyId
     * @return
     */
    @Override
    public List<MeasureRecord> listByConditionPage(Long accuracyId){
        QueryWrapper<MeasureRecord> qw=new QueryWrapper<>();
        if(accuracyId!=null){
            qw.and(wrapper -> wrapper.eq("accuracy_mange_id", accuracyId));
        }

        qw.orderByDesc("measure_date");
        return measureRecordMapper.selectList(qw);
    }

    /**
     * id批量查询
     * @param ids
     * @return
     */
    @Override
    public List<MeasureRecordExcel> listByIds(List<Long> ids) {
        List<MeasureRecordDto> measureRecordDtos=measureRecordMapper.listByIds(ids);
        List<MeasureRecordExcel> excels=new ArrayList<>();
        for(MeasureRecordDto mrd:measureRecordDtos){
            MeasureRecordExcel mre=new MeasureRecordExcel();
            mre.setAccuracyMangeName(mrd.getAccuracyMangeName());
            mre.setAnalysis(mrd.getAnalysis());
            mre.setCycle(mrd.getCycle());
            mre.setDepartment(mrd.getDepartment());
            mre.setDeviceName(mrd.getDeviceName());
            mre.setMeasureDate(DateUtils.transferLongToDate("yyyy-MM-dd HH:mm:ss",mrd.getMeasureDate()));
            mre.setMeasureMan(mrd.getMeasureMan());
            mre.setMeasurePoint(mrd.getMeasurePoint());
            mre.setModelNumber(mrd.getModelNumber());
            mre.setValue(mrd.getValue());
            excels.add(mre);
        }
        return excels;
    }
}
